Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Data
Imports DotNetNuke.Entities.Portals
Imports DotNetNuke.Entities.Tabs
Imports DotNetNuke.Entities.Users
Imports DotNetNuke.Framework
Imports DotNetNuke.Modules
Imports DotNetNuke.Security
Imports DotNetNuke.Entities.Modules

Partial Class Settings
    Inherits ModuleSettingsBase
    ' Methods
    Public Overrides Sub LoadSettings()
        Try
            lblProductGroups.Text = Services.Localization.Localization.GetString("ProductGroups.Text", Me.LocalResourceFile)
            chbPricing.Text = Services.Localization.Localization.GetString("Pricing.Text", Me.LocalResourceFile)
            If Not Me.Page.IsPostBack Then
                Dim left As String = Convert.ToString(Me.Settings.Item("ProductGroupId"))
                Dim pricing As String = Convert.ToString(Me.Settings.Item("Pricing"))
                If left.Equals(String.Empty) Then
                    left = "0"
                End If
                If pricing.Equals(String.Empty) Then
                    pricing = "TRUE"
                End If

                Dim controller As New ProductGroupController
                ddlProductGroups.DataSource = controller.GetProductGroupsByModuleId(Me.ModuleId)
                ddlProductGroups.DataTextField = "ProductGroup"
                ddlProductGroups.DataValueField = "ProductGroupId"
                ddlProductGroups.DataBind()
                ddlProductGroups.Items.Insert(0, Services.Localization.Localization.GetString("Select.Text", Me.LocalResourceFile))
                ddlProductGroups.Items.Item(0).Value = "0"
                ddlProductGroups.Items.Item(0).Selected = True
                Dim info As New ProductGroupInfo
                info.ProductGroupId = -1
                Dim productGroupsByPortalId As IDataReader = controller.GetProductGroupsByModuleId(Me.ModuleId)
                Do While productGroupsByPortalId.Read
                    If Convert.ToString(productGroupsByPortalId.Item("ProductGroupId")).Equals(left) Then
                        info.ProductGroupId = CInt(productGroupsByPortalId.Item("ProductGroupId"))
                        info.ProductGroup = Convert.ToString((productGroupsByPortalId.Item("ProductGroup")))
                    End If
                Loop
                productGroupsByPortalId.Close()
                If Me.ddlProductGroups.Items.Contains(New ListItem(info.ProductGroup, info.ProductGroupId.ToString)) Then
                    Me.ddlProductGroups.SelectedValue = left
                End If
                chbPricing.Checked = CBool(pricing)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Overrides Sub UpdateSettings()
        Try
            Me.Page.Validate()
            If Me.Page.IsValid Then
                Dim mc As New ModuleController()
                mc.UpdateModuleSetting(Me.ModuleId, "ProductGroupId", Me.ddlProductGroups.SelectedValue)
                mc.UpdateModuleSetting(Me.ModuleId, "Pricing", Me.chbPricing.Checked)
            End If
        Catch ex As Exception

        End Try
    End Sub


End Class

